﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microhard.Permission.Interface;
using Microsoft.Practices.Unity;
using Microhard.Permission.MVCFilter;
using Microhard.WebUI.Models;
using Telerik.Web.Mvc;
using Microhard.Plat.CompanyChargingMng.Models;
using Microhard.Plat.CompanyChargingMng.Interfaces;

namespace Microhard.Plat.CRM.WebUI.Areas.PlatMng.Controllers
{
    public class CompanyController : MicroHardBaseController<CompanyModel>
    {
        private ICompany _resp = null;
        [Dependency]
        public ICompany Category
        {
            set
            {
                base._repository = value;
                _resp = value;
            }
            get
            {
                return _resp;
            }
        }

        [MVCFilterAtrForLogon()]
        [MVCFilterAtrForResourcePermission(OperationKeyName = "Index")]
        public ActionResult GetHQList(AttriubteOfSelectList ctrAttr)
        {
            var comp = _resp.GetHQCompany();
            ctrAttr.Data = comp.Select(r => new SelectData
            {
                ID = r.CompanyID.ToString(),
                Name = r.Name
            }).ToList();
            return View("SelectList", ctrAttr);
        }

        [MVCFilterAtrForLogon()]
        [MVCFilterAtrForResourcePermission(OperationKeyName = "Index")]
        public ActionResult SelectCmp(AttributeOfWindow aowModel)
        {
            int totalCount;
            var rtn = _resp.Query(new CompanyModel(), 0, 10, out totalCount);
            aowModel.Data = new GridModel()
            {
                Data = rtn,
                Total = totalCount
            };
            return View(aowModel);
        }
    }
}
